package com.ruoyi.framework.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.ruoyi.common.utils.SecurityUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Description:
 *
 * @author: EDY
 * @since: 2024/6/29
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime", new Date(), metaObject);
        try {
            String username = SecurityUtils.getUsername();
            this.setFieldValByName("createBy", username, metaObject);
        } catch (Exception e) {

        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", new Date(), metaObject);
        try {
            String username = SecurityUtils.getUsername();
            this.setFieldValByName("updateBy", username, metaObject);
        } catch (Exception e) {

        }
    }


}
